<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?python
    from mnemoply.utils import replace_query_var
    from genshi.input import HTML
?>

<thead xmlns:py="http://genshi.edgewall.org/">
<form action="save_list_args" method="POST">
    <tr>
        <td> &nbsp;</td>
        <td py:for="column_index, col in enumerate(visible_columns)"
            onmouseout="bgColor=''" onmouseover="bgColor='#bbbbee'"
            nowrap="nowrap">
            <?python
                sort_symbol = ''
                if order_by == col.name:
                    if order_asc == 1:
                        sort_symbol = '&#8593; '
                    else:
                        sort_symbol = '&#8595; '
                    href = replace_query_var('save_list_args', asc=int(not order_asc))
                else:
                    href = replace_query_var('save_list_args', sort=col.name)
                href_move_right = replace_query_var('save_list_args', move_right_vc=visible_columns.index(col))
                href_move_left  = replace_query_var('save_list_args', move_left_vc=visible_columns.index(col))
            ?>
            <a py:if="column_index > 0" class="move_vc" href="${href_move_left}">←</a>
            <span py:if="column_index == 0">&nbsp;&nbsp;&nbsp;</span>
            <a href="${href}">
                <span>${HTML(sort_symbol)}</span>
                <span class="col_caption"><pre>${col.caption}</pre></span>
            </a>

            <a py:if="len(visible_columns) - 1 > column_index"
                class="move_vc" href="${href_move_right}">→</a>
            <span py:if="column_index == len(visible_columns) - 1">&nbsp;&nbsp;&nbsp;</span>
        </td>
        <td>
            <input type='button' value='...' onclick=' toggleDisplay("colset");'/>
            <div style='position: absolute;'>
                <div class='popup' id='colset'>
                    <h2>Settings</h2>
                    <div py:for="n, col in enumerate(columns)">
                        <input type='checkbox' 
                               value="${n}"
                               py:content="col.caption"
                               py:if="col not in visible_columns"
                               name="visible"/>
                    
                        <input  type='checkbox' 
                                value="${n}"
                                py:content="col.caption"
                                py:if="col in visible_columns"
                                checked='checked'
                                name="visible"/>
                    </div>
                    <label class="fieldlabel">Records per page</label>
                    <select name="per_page">
                        <option py:for="n in per_page_values"
                                value="${n}"
                                py:content="n"
                                py:attrs="n == per_page and {'selected':'selected'} or {}"/>
                    </select>
                    <br/>
                    <input type='submit' value='${_("Apply")}' onclick=' toggleDisplay("colset");'/>
                    <div>
                        <a href="save_list_args?clear=1">Reset settings to defaults</a>
                        <br/>
                        <br/>
                    </div>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <img src="/static/images/dots.gif" class="pseudo_link" border="0" vspace="0" hspace="0"
                onclick="montre('smenu9');" onmouseout="hide_menu_delay();"/>
                <table id="smenu9" onmouseover="hide_menu_cancel();" onmouseout="hide_menu_delay();">
                    <tr onmouseout="bgColor=''" onmouseover="bgColor='#bbbbee'">
                        <td onclick="createURL();return false;" class="pseudo_link">
                            <span>Save As</span>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr class="menu_item" py:for="n, fil in enumerate(user_filters)"
                        onmouseout="bgColor=''" onmouseover="bgColor='#bbbbee'">
                        <td class="pseudo_link" onclick="document.location='load_filter?load_filter=${n}'">${fil.name}</td>
                        <td width="10px"><a href="delete_filter?delete_filter=${n}">x</a></td>
                    </tr>
                </table>
        </td>
        
        <td py:for="col in visible_columns">
            <input  id="${col.name}"
                    name="${str('flt_' + col.name)}"
                    value="${str(filters.get(col.name, ''))}"
                    size="${getattr(col, 'size', '15')}" />
        </td>
        <td>
            <button type="submit">
                <img src="/static/images/enter.gif" border="0" hspace="0" vspace="0" />
            </button>
        </td>
    </tr>
</form>
</thead>

